/*******************************************************************************
 * Odbaul Mobile Client - Xml.java 
 * Copyright (c) Vernalis Systems pvt ltd  2009 
 * This file is licensed from, and is a trade secret of:
 * 	Vernalis Systems pvt ltd
 * 	1,Shakthi Nagar
 * 	Mount Poonamallee road Porur
 * 	Chennai -116
 * TERMS OF USE: Refer your Software License Agreement
 *  Elton Kent - initial API and implementation
 ******************************************************************************/
package com.aphrodite.parser;

//import java.io.*;
//import java.util.*;

/**
 * A class containing several static xml methods, mainly for escaping special
 * characters like angle brakets and quotes. This class contains also some
 * (partially shared) constants for the parser and kDOM.
 */

public final class Xml {

	/** Integer constant for comments */

	public static final int COMMENT = 1;

	/** Integer constant for doctype */

	public static final int DOCTYPE = 2;

	/** Integer constant for elements */

	public static final int ELEMENT = 4;

	/** forces escaping of all character coded greater than 127 */

	static int ENCODE_128 = 2;

	/** minimum escaping, quotes are not escaped */

	static final int ENCODE_MIN = 0;

	/** forces escaping of quotes */

	static final int ENCODE_QUOT = 1;

	/**
	 * Integer constant returned by ParseEvent.getType if the end of the
	 * document has been reached
	 */

	public static final int END_DOCUMENT = 8;

	/** Integer constant assigned to an EndTag parse event */

	public static final int END_TAG = 16;

	public static final String NO_NAMESPACE = "";

	/** Integer constant assigned to a processing instruction */

	public static final int PROCESSING_INSTRUCTION = 32;

	/** XmlReader return value before the first call to next or skip */

	public static final int START_DOCUMENT = 0;

	/** Integer constant assigned to StartTag parse event */

	public static final int START_TAG = 64;

	/** Integer constant assigned to text nodes and events */

	public static final int TEXT = 128;

	/** Constant identifying wap extension events */

	static final int WAP_EXTENSION = 1024;

	/** Integer constant for whitespace nodes and events */

	public static final int WHITESPACE = 256;

	/** convenience method for encode (String raw, ENCODE_MIN) */

	/*
	 * public static String encode (String raw) { return encode (raw,
	 * ENCODE_MIN); }
	 */

	/*
	 * encodes an attribute with the given name and value. A single space is
	 * inserted before the name of the attribute
	 * 
	 * public static String encodeAttr (String name, String value) { return
	 * " "+name+"=\"" + encode (value, ENCODE_QUOT) + "\""; }
	 */

	/** encodes a string escaping less than etc. */

	/*
	 * public static String encode (String raw, int flags) {
	 * 
	 * int len = raw.length ();
	 * 
	 * StringBuffer cooked = new StringBuffer (raw.length ());
	 * 
	 * for (int i = 0; i < len; i++) { char c = raw.charAt (i);
	 * 
	 * switch (c) { case '<': cooked.append ("&lt;"); break; case '>':
	 * cooked.append ("&gt;"); break; case '&': cooked.append ("&amp;"); break;
	 * case '"': { if ((flags & ENCODE_QUOT) != 0) cooked.append ("&quot;");
	 * else cooked.append ('"'); } break; default: if (c >= 128 && ((flags &
	 * ENCODE_128) != 0)) cooked.append ("&#"+((int) c)+";"); else cooked.append
	 * (c); } } return cooked.toString (); }
	 */

	/*
	 * quotes a string by adding quote chars at the beginning and the end and
	 * escaping all quotes and XML special chars contained in the string
	 * 
	 * public static String quote (String q) { return "\"" + encode (q,
	 * ENCODE_QUOT) + "\""; }
	 */

	/*
	 * like String.trim, but additionally all groups of one or more whitespace
	 * characters in the string are replaced by a single space (0x040)
	 * 
	 * public static String trim (String s) {
	 * 
	 * char [] buf = new char [s.length ()]; boolean ignoring = false; int
	 * targetPos = 0;
	 * 
	 * for (int i = 0; i < s.length (); i++) { char c = s.charAt (i);
	 * 
	 * if (c <= ' ') ignoring = true; else { if (ignoring) { if (targetPos != 0)
	 * buf [targetPos++] = ' '; ignoring = false; } buf [targetPos++] = c; } }
	 * 
	 * return new String (buf, 0, targetPos); }
	 */
}
